package com.sangeng.controller;


import com.sangeng.domain.ResponseResult;
import com.sangeng.dto.AddArticleDto;
import com.sangeng.service.IArticleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/content/article")
public class ArticleController {

    @Autowired
    private IArticleService articleService;

    @PostMapping
    public ResponseResult add(@RequestBody AddArticleDto articleDto) {
        return articleService.add(articleDto);
    }

    // 查询文章列表
    @RequestMapping("/list")
    public ResponseResult articleList(Integer pageNum, Integer pageSize, String title, String summary) {
        return articleService.articleListAdmin(pageNum, pageSize, title, summary);
    }

    // 查询文章详情
    @GetMapping("/{id}")
    public ResponseResult getInfo(@PathVariable(name = "id") Long id) {
        return articleService.getArticleDtoById(id);
    }


    // 更新文章接口
    @PutMapping
    public ResponseResult edit(@RequestBody AddArticleDto articleDto) {
        return articleService.edit(articleDto);
    }

    // 删除文章
    @DeleteMapping("/{id}")
    public ResponseResult remove(@PathVariable(name = "id") Long id) {
         articleService.removeById(id);
         return ResponseResult.okResult();
    }

}
